; REMDRV.MAC - A BASTARDIZATION OF CONREM
; CREATED 10/05/85 BY ESKAY (AS ALWAYS)
; VERSION 23 AS OF 10/11/85
;
	NAME	('RemDrv')
;
; ANOTHER ENHANCED TURBODOS MODULE BY ESKAY
; IN ADDITION TO THE DESCRIPTION OF T-FCN 33, REMOTE CONSOLE I/O,
; THE FOLLOWING IS NOW POSSIBLE:
; - SET/QUERY REMOTE BAUD RATES
; - REMOTE CHANNEL I/O
;
; ADDITIONAL SYNTAX:	(C-REGISTER = 33)
; REG	CONT	FUNCTION
;  D	0FE	ATTACH CHANNEL IN B, RETURN A=FF=BUSY
;  D	0FD	DETACH CHANNEL IN B
;  D	0FC	SET BAUD FOR CHANNEL IN B, FROM E
;  D	0FB	GET BAUD FOR CHANNEL IN B, RETURN IN A
;  D	0FA	RETURN INPUT DATA FROM CHANNEL B,
;		IF BIT 7 SET ON B, OUTPUT BYTE IN E
;
.Z80
;
	ASEG				; GET SERIAL # STRAIGHT
	PUBLIC	?ORIG?,?UNIT?
?ORIG?	EQU	24
?UNIT?	EQU	1
;
	CSEG
;
RCHNTY:	LD	A,(IX+32H)		; GET MODE BYTE
	CP	0FEH			; ATTACH?
	JP	Z,ATTACH
	CP	0FDH			; DETACH?
	JP	Z,DETACH
	CP	0FCH			; SET BAUD
	JP	Z,SETBD
	CP	0FBH			; GET BAUD
	JP	Z,GETBD
	CP	0FAH			; GET INPUT
	JP	Z,DOIO
;
; CONTINUE WITH CONREM STUFF
;
	LD	A,(IX+3BH)
	JP	RCFCN##+3		; CONTINUE
;
;	+------------------------+
;	| COMM CHANNEL I/O STUFF |
;	+------------------------+
;
; ATTACH TO CHANNEL
;
ATTACH:	CALL	GETCHN			; GET CHANNEL NUMBER INTO DE
	LD	HL,BUSYV		; POINT TO BUSY VECTOR
	ADD	HL,DE
	LD	A,(HL)
	LD	(HL),0FFH		; PRESET BUSY
	OR	A			; TEST BUSY
	JP	NZ,EXITA##		; RETURN A=FF IF BUSY
	LD	HL,ATTV			; POINT TO ATTACH TABLE
	JR	GETVEC			; GET VECTOR
;
; DETACH FROM CHANNEL
;
DETACH:	CALL	GETCHN			; GET CHANNEL NUMBER
	LD	HL,BUSYV		; POINT TO BUSY VECTOR
	ADD	HL,DE
	LD	(HL),0			; SET CHANNEL CLEAR
	LD	HL,DETV
	JR	GETVEC
;
; SET CHANNEL BAUD RATE
;
SETBD:	CALL	GETCHN			; GET CHANNEL NUMBER
	LD	HL,SETBV		; POINT TO SETBAUD VECTORS
	JR	GETVEC			; GET VECTOR
;
; GET BAUD RATE
;
GETBD:	CALL	GETCHN			; GET CHANNEL #
	LD	HL,GETBV		; POINT TO GETBAUD VECTORS
	JR	GETVEC
;
; DO I/O
;
DOIO:	CALL	GETCHN			; GET CHANNEL #
	RES	7,E			; STRIO OUTPUT FLAG IF SET
	LD	HL,IOV
;
; GET VECTOR
;
GETVEC:	ADD	HL,DE
	ADD	HL,DE
	LD	E,(HL)
	INC	HL
	LD	D,(HL)
	CALL	TSTUND##		; TEST UNDEFINED
	LD	A,0FEH			; PRELOAD FALSE
	JR	NZ,.XCUTE
	CALL	GETCHN
	LD	HL,BUSYV
	ADD	HL,DE
	LD	(HL),0
	JP	EXITA##
.XCUTE:	EX	DE,HL
	JP	(HL)
;
GETCHN:	LD	E,(IX+30H)		; GET CHANNEL
	LD	D,0
	RET
;
	COMMON	/?INIT?/
;
DSKIN@::
	LD	HL,RCHNTY
	LD	A,0C3H
	LD	(RCFCN##),A
	LD	(RCFCN##+1),HL
	RET
;
	DSEG
;
; REMDRV DATA AREA
;
BUSYV:	DB	0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0	; BUSY VECTORS
ATTV:	DW	ATACHA##
	DW	ATACHB##
	DW	ATACHC##
	DW	ATACHD##
	DW	ATACHE##
	DW	ATACHF##
	DW	ATACHG##
	DW	ATACHH##
	DW	ATACHI##
	DW	ATACHJ##
	DW	ATACHK##
	DW	ATACHL##
	DW	ATACHM##
	DW	ATACHN##
	DW	ATACHO##
	DW	ATACHP##
;
DETV:	DW	DETAA##
	DW	DETAB##
	DW	DETAC##
	DW	DETAD##
	DW	DETAE##
	DW	DETAF##
	DW	DETAG##
	DW	DETAH##
	DW	DETAI##
	DW	DETAJ##
	DW	DETAK##
	DW	DETAL##
	DW	DETAM##
	DW	DETAN##
	DW	DETAO##
;
SETBV:	DW	SETBAA##
	DW	SETBAB##
	DW	SETBAC##
	DW	SETBAD##
	DW	SETBAE##
	DW	SETBAF##
	DW	SETBAG##
	DW	SETBAH##
	DW	SETBAI##
	DW	SETBAJ##
	DW	SETBAK##
	DW	SETBAL##
	DW	SETBAM##
	DW	SETBAN##
	DW	SETBAO##
	DW	SETBAP##
;
GETBV:	DW	GETBDA##
	DW	GETBDB##
	DW	GETBDC##
	DW	GETBDD##
	DW	GETBDE##
	DW	GETBDF##
	DW	GETBDG##
	DW	GETBDH##
	DW	GETBDI##
	DW	GETBDJ##
	DW	GETBDK##
	DW	GETBDL##
	DW	GETBDM##
	DW	GETBDN##
	DW	GETBDO##
	DW	GETBDP##
;
IOV:	DW	INOUTA##
	DW	INOUTB##
	DW	INOUTC##
	DW	INOUTD##
	DW	INOUTE##
	DW	INOUTF##
	DW	INOUTG##
	DW	INOUTH##
	DW	INOUTI##
	DW	INOUTJ##
	DW	INOUTK##
	DW	INOUTL##
	DW	INOUTM##
	DW	INOUTN##
	DW	INOUTO##
	DW	INOUTP##
;
	END

	DW	ATACHI##
	DW	ATACHJ##
	DW	ATACHK##
	DW	ATACHL##
	D